<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // ES5
        // function Person(name, age) {
        //     this.name = name;
        //     this.age = age;
        // }
        // Person.prototype.fn = function(){
        //     console.log('fn');
        // }
        // var p = new Person('张三',20)
        // console.log(p);

        // ES6
        class Person{
            // constructor 会在实例化的时候执行
            constructor(name,age){
                this.name = name
                this.age = age
                this.fn();
            }
            fn(){
                console.log('fn');
            }
            getName(){
                return this.name
            }
            setName(name){
                this.name = name
            }
        }
        var p = new Person('张三',20)
        console.log(p);
        console.log(typeof Person);//function
        p.setName('李四')
        console.log(p.getName());

        // 属性的多种定义方式
        // class Person{
        //     name = '张三'
        // }
        // let p = new Person();
        // console.log(p);
    </script>

</body>

</html>